package com.weddingee.action.home;

import com.weddingee.action.base.BaseAction;
import com.weddingee.model.Other;
import com.weddingee.dao.base.BaseDao;
import com.weddingee.dao.home.OtherDao;
import com.weddingee.dto.ViewDto;
import com.weddingee.util.DaoFactory;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.weddingee.model.News;

public class OtherAction extends BaseAction{
	private OtherDao otherDao = (OtherDao)DaoFactory.create(3);
	private Long otherId;
	private String othername;
	private String type;
	private String url;
	private String message1;
	private String message2;
	private String message3;
	private String message4;
	private String message5;
	private String message6;
	private String message7;
	private String introduce;
	private int page;
	private int count;
	private int totalPage;		//当前查询条件的总数
	private ViewDto view = new ViewDto();
	
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	
	
   //add
  public String add(){
	      Other other = new Other();
	      if(null==othername || othername==""){
	    	  othername="婚礼专用";
	      }
	  	  other.setOthername(othername);
	      other.setType(type);
	  	  other.setUrl(url);
		  other.setMessage1(message1);
		  other.setMessage2(message2);
		  other.setMessage3(message3);
		  other.setMessage4(message4);
		  other.setMessage5(message5);
		  other.setMessage6(message6);
		  other.setMessage7(message7);
		  other.setIntroduce(introduce);
	  otherDao.save(other);
	  return SUCCESS;
  }
  
  //delete
  public String delete(){
	  otherDao.delete(otherId);
	  return SUCCESS;
	  
  }
  
  //list
  public String list(){
	  if(page==0){
		  page=1;
	  }
		count = 54;
	 List<Other> otherList = otherDao.listOther(page,type);
	 int totalCount = otherList.size();
		if( totalCount%count != 0 )
		{
			totalPage = totalCount/count + 1;
		}else{
			totalPage = totalCount/count;
		}
	 System.out.println(otherList);
	  return SUCCESS;
  }
  

//update
  public String update(){
	  Other other = otherDao.find(otherId);
     
	  other.setOthername(othername);
	  other.setType(type);
	  other.setUrl(url);
	  other.setIntroduce(introduce);
	  if(null != message1){
		  other.setMessage1(message1);
	  }
	  if(null != message2){
		  other.setMessage2(message2);
	  }
	  if(null != message3){
		  other.setMessage3(message3);
	  }
	  if(null != message4){
		  other.setMessage4(message4);
	  }
	  if(null != message5){
		  other.setMessage5(message5);
	  }
	  if(null != message6){
		  other.setMessage6(message6);
	  }
	  other.setMessage7(message7);
	  otherDao.update(other);
	  return SUCCESS;
  }
  
  //find
  public String find(){
	  Other other = new Other();
	  other = otherDao.find(otherId);
	 
	  view.setData(other);
	  view.setMsg(SUCCESS);
	  return SUCCESS;
  }
  
  
public Long getOtherId() {
	return otherId;
}

public void setOtherId(Long otherId) {
	this.otherId = otherId;
}

public String getOthername() {
	return othername;
}

public ViewDto getView() {
	return view;
}

public void setOthername(String othername) {
	this.othername = othername;
}


public String getMessage1() {
	return message1;
}

public void setMessage1(String message1) {
	this.message1 = message1;
}

public String getMessage2() {
	return message2;
}

public void setMessage2(String message2) {
	this.message2 = message2;
}

public String getMessage3() {
	return message3;
}

public void setMessage3(String message3) {
	this.message3 = message3;
}

public String getMessage4() {
	return message4;
}

public void setMessage4(String message4) {
	this.message4 = message4;
}

public String getMessage5() {
	return message5;
}

public void setMessage5(String message5) {
	this.message5 = message5;
}

public String getMessage6() {
	return message6;
}

public void setMessage6(String message6) {
	this.message6 = message6;
}

public void setOtherDao(OtherDao otherDao) {
	this.otherDao = otherDao;
}



public String getType() {
	return type;
}

public void setType(String type) {
	this.type = type;
}

public String getUrl() {
	return url;
}

public void setUrl(String url) {
	this.url = url;
}

public String getMessage7() {
	return message7;
}

public void setMessage7(String message7) {
	this.message7 = message7;
}

public String getIntroduce() {
	return introduce;
}

public void setIntroduce(String introduce) {
	this.introduce = introduce;
}

public int getTotalPage() {
	return totalPage;
}

public void setTotalPage(int totalPage) {
	this.totalPage = totalPage;
}


}
